package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONArray;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.ElderlyApartmentVisitRecords;
import com.elder.business.service.IElderlyApartmentVisitRecordsService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 探访记录Controller
 * 
 * @author zyk
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/visitRecords")
public class ElderlyApartmentVisitRecordsController extends BaseController
{
    @Autowired
    private IElderlyApartmentVisitRecordsService elderlyApartmentVisitRecordsService;

    /**
     * 查询探访记录列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String visitorName,String elderName,String startTime,String endTime,Integer pageNum,Integer pageSize)
    {
        return elderlyApartmentVisitRecordsService.selectElderlyApartmentVisitRecordsList(visitorName,elderName,startTime,endTime,pageNum,pageSize);
    }

    /**
     * 导出探访记录列表
     */
//    @PreAuthorize("@ss.hasPermi('business:visitRecords:export')")
//    @Log(title = "探访记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ElderlyApartmentVisitRecords elderlyApartmentVisitRecords)
//    {
//        List<ElderlyApartmentVisitRecords> list = elderlyApartmentVisitRecordsService.selectElderlyApartmentVisitRecordsExportList(elderlyApartmentVisitRecords);
//        ExcelUtil<ElderlyApartmentVisitRecords> util = new ExcelUtil<ElderlyApartmentVisitRecords>(ElderlyApartmentVisitRecords.class);
//        util.exportExcel(response, list, "探访记录数据");
//    }

    /**
     * 获取探访记录详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elderlyApartmentVisitRecordsService.selectElderlyApartmentVisitRecordsById(id));
    }

    /**
     * 新增探访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visitRecords:add')")
    @Log(title = "探访记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElderlyApartmentVisitRecords elderlyApartmentVisitRecords)
    {
        return toAjax(elderlyApartmentVisitRecordsService.insertElderlyApartmentVisitRecords(elderlyApartmentVisitRecords));
    }

    /**
     * 修改探访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visitRecords:edit')")
    @Log(title = "探访记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElderlyApartmentVisitRecords elderlyApartmentVisitRecords)
    {
        return toAjax(elderlyApartmentVisitRecordsService.updateElderlyApartmentVisitRecords(elderlyApartmentVisitRecords));
    }

    /**
     * 删除探访记录
     */
    @PreAuthorize("@ss.hasPermi('business:visitRecords:remove')")
    @Log(title = "探访记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elderlyApartmentVisitRecordsService.deleteElderlyApartmentVisitRecordsByIds(ids));
    }
}
